package com.lz.ccjdemo.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.lz.ccjdemo.greendao.data.WarehouseData;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "WAREHOUSE_DATA".
*/
public class WarehouseDataDao extends AbstractDao<WarehouseData, Long> {

    public static final String TABLENAME = "WAREHOUSE_DATA";

    /**
     * Properties of entity WarehouseData.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Warehouse_number = new Property(1, String.class, "warehouse_number", false, "WAREHOUSE_NUMBER");
        public final static Property Warehouse_name = new Property(2, String.class, "warehouse_name", false, "WAREHOUSE_NAME");
        public final static Property Content = new Property(3, String.class, "content", false, "CONTENT");
        public final static Property Dish_id = new Property(4, Long.class, "dish_id", false, "DISH_ID");
        public final static Property Des = new Property(5, String.class, "des", false, "DES");
    }

    private Query<WarehouseData> dishData_WarehouseQuery;

    public WarehouseDataDao(DaoConfig config) {
        super(config);
    }
    
    public WarehouseDataDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"WAREHOUSE_DATA\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"WAREHOUSE_NUMBER\" TEXT," + // 1: warehouse_number
                "\"WAREHOUSE_NAME\" TEXT," + // 2: warehouse_name
                "\"CONTENT\" TEXT," + // 3: content
                "\"DISH_ID\" INTEGER," + // 4: dish_id
                "\"DES\" TEXT);"); // 5: des
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"WAREHOUSE_DATA\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, WarehouseData entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String warehouse_number = entity.getWarehouse_number();
        if (warehouse_number != null) {
            stmt.bindString(2, warehouse_number);
        }
 
        String warehouse_name = entity.getWarehouse_name();
        if (warehouse_name != null) {
            stmt.bindString(3, warehouse_name);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(4, content);
        }
 
        Long dish_id = entity.getDish_id();
        if (dish_id != null) {
            stmt.bindLong(5, dish_id);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(6, des);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, WarehouseData entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String warehouse_number = entity.getWarehouse_number();
        if (warehouse_number != null) {
            stmt.bindString(2, warehouse_number);
        }
 
        String warehouse_name = entity.getWarehouse_name();
        if (warehouse_name != null) {
            stmt.bindString(3, warehouse_name);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(4, content);
        }
 
        Long dish_id = entity.getDish_id();
        if (dish_id != null) {
            stmt.bindLong(5, dish_id);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(6, des);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public WarehouseData readEntity(Cursor cursor, int offset) {
        WarehouseData entity = new WarehouseData( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // warehouse_number
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // warehouse_name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // content
            cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4), // dish_id
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // des
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, WarehouseData entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setWarehouse_number(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setWarehouse_name(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setDish_id(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
        entity.setDes(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(WarehouseData entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(WarehouseData entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(WarehouseData entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "warehouse" to-many relationship of DishData. */
    public List<WarehouseData> _queryDishData_Warehouse(Long dish_id) {
        synchronized (this) {
            if (dishData_WarehouseQuery == null) {
                QueryBuilder<WarehouseData> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Dish_id.eq(null));
                dishData_WarehouseQuery = queryBuilder.build();
            }
        }
        Query<WarehouseData> query = dishData_WarehouseQuery.forCurrentThread();
        query.setParameter(0, dish_id);
        return query.list();
    }

}
